<style lang="scss" scoped>
main {
  padding: 0 0 0.64rem;
  .apple_id {
    padding: 0.5rem 0.2rem 0;
  }
  ul {
    padding: 0 0.2rem 0 0.2rem;
    .code {
      padding: 0.2rem 0 0.2rem 0.3rem;
      background: #fff;
      z-index: 2;
      right: 0;
      bottom: -0.2rem;
      & > div {
        height: 0.3rem;
        padding: 0 0 0 0.2rem;
        & > div {
          border: 1px solid #e12825;
          padding: 0.05rem 0.16rem;
          position: relative;
          top: 0.02rem;
        }
      }
    }
    li {
      height: 0.45rem;
      padding: 0.58rem 0 0.08rem;
      display: flex;
      // justify-content: center;
      align-items: flex-end;
      div {
        padding-right: 0.08rem;
      }
    }
  }
}
footer {
  padding-top: 1rem;
}
.border-l:after {
  content: " ";
  position: absolute;
  left: -1px;
  top: 0;
  width: 1px;
  height: 100%;
  border-left: 1px solid #e12825;
  color: #e12825;
  -webkit-transform-origin: 0 100%;
  transform-origin: 0 100%;
  -webkit-transform: scaleX(0.5);
  transform: scaleX(0.5);
}
</style>

<template>
  <div class="forget_pwd">
    <main class="box1 bgfff">
      <div class="apple_id">
        已绑定手机
        <span class="cred margin-l5">{{tel | toMobile}}</span>
      </div>
      <ul>
        <li class=" flex-col box-sizing border-b">
          <input type="tel" class="box1" v-model="code" placeholder="请输入短信验证码">
          <div class="position-a code">
            <div class="border-l">
              <div class="box-center cred bor-r" @click="getCode">{{codeText}}</div>
            </div>
          </div>
        </li>
      </ul>
    </main>
    <footer class="box-center footer font-14 box-center">
      <div class="cfff box-center" @click="toRouter">下一步</div>
    </footer>
  </div>
</template>

<script>
export default {
  name: "forget_pwd",
  data() {
    return {
      tel: "",
      code: "",
      codeText: "获取"
    };
  },
  mounted() {
    let that = this;
    this.$nextTick(() => {
      that.tel = that.getCache("userInfo").mobile;
    });
  },
  methods: {
    toRouter() {
      if (!this.code) {
        this.layer("请输入验证码");
        return;
      }
      let that = this;
      this.$router.push({
        path: "/set_pay",
        query: {
          id: that.code
        }
      });
    },
    // 获取验证码
    getCode() {
      let that = this;
      let phone = this.tel;

      this.http
        .get("user/getCode", {
          phone: phone
        })
        .then(res => {
          let time = 60,
            $time;
          $time = setInterval(function() {
            that.hasCodeText = true;
            --time;
            that.codeText = time + "s后获取";
            if (time <= 0) {
              that.hasCodeText = false;
              that.codeText = "获取";
              clearInterval($time);
              console.log("清除定时器");
            }
          }, 1000);
        })
        .catch(res => {
          console.log("请求失败22222222222" + JSON.stringify(res));
        });
    }
  }
};
</script>


